<%--
  Created by IntelliJ IDEA.
  User: 说好的幸福呢
  Date: 2021/5/18
  Time: 11:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<script type="text/javascript" src="js/jquery.js"></script>
<html>
<head>
    <title>学生查询页面</title>

    <style type="text/css">
        td{
            text-align: center;
            width: 125px;
        }
        .c2{
            margin-left: 40px;
            margin-bottom: 40px;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $("#checkAll").click(function () {
                $(".c1").prop("checked",$(this).prop("checked"));
            });
            $(".c1").click(function () {
               var a = $(".c1:checked").length;
               var b = $(".c1").length;
               $("#checkAll").prop("checked",a == b);
            });

            $("#batchDel").click(function () {

                $arr = $(".c1:checked");
                var array = new Array()
                $arr.each(function (i,dom) {
                    array[i] = $(dom).val();
                });
                var ids = array.join(',');
                if($arr.length>=1){
                    //发送批量删除请求
                    location.href="bachDelStu.do?ids="+ids;
                }else{
                    alert("至少选中一个");
                }



            });

        });
    </script>
</head>
<body>
<br/>
<center>
    <form action="queryStu.do" method="post">
        姓名：<input type="text" name="name"/>&nbsp;&nbsp;&nbsp;
        性别
        <select name="gender">
            <option value="-1">请选择</option>
            <option value="男">男</option>
            <option value="女">女</option>
        </select>&nbsp;&nbsp;&nbsp;
        <input type="submit" value="查询"/>
    </form>
</center>
<br/>
<h4 align="center">${sessionScope.admin},欢迎访问学生管理系统</h4>
<c:if test="${sessionScope.stuList == null}">
    <c:redirect url="queryStu.do"/>
</c:if>
<input type="button" id="batchDel" value="批量删除" style="margin-left: 150px"/>
<input type="button" value="添加" style="margin-left: 20px" onclick="location.href = 'addStu.jsp'">
<br/>
<br/>
<table border="1px" width="80%" align="center" cellpadding="0"
       cellspacing="0">
    <tr>
        <th><input type="checkbox" id="checkAll" />全选/全不选</th>
        <th>学号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>生日</th>
        <th>爱好</th>
        <th>头像</th>
        <th>操作</th>
    </tr>
    <!-- 遍历学生的信息 -->
    <c:forEach items="${sessionScope.stuList}" var="s">
        <tr>
            <td><input type="checkbox" class="c1" value="${s.id}"/></td>
            <td>${s.id}</td>
            <td>${s.name}</td>
            <td>${s.gender}</td>
            <td>${s.bir}</td>
            <td>${s.hobby}</td>
            <td>
                <img src="/upload/${s.photo}" height="80px" width="58px">
            </td>
            <td>
                <a href="updateStuById.do?id=${s.id}">修改</a>
            </td>
        </tr>
    </c:forEach>
</table>
</body>
</html>
